package com.example.myapplication.tack_22.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.tack_22.data.AllRoutesData;
import com.example.myapplication.tack_22.data.RouteData;

import java.util.List;

public class AllRouteAdapter extends RecyclerView.Adapter<AllRouteAdapter.My> {
    private List<AllRoutesData.DataDTO> list;
    private Context context;
    private View view;

    public AllRouteAdapter(List<AllRoutesData.DataDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_22_all_routes,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        if(!TextUtils.isEmpty(list.get(position).getLineName())){
            holder.lineName.setText(list.get(position).getLineName());
        }
        int randomColor = Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255));
        holder.color.setBackgroundColor(randomColor);



    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView lineName;
        private TextView color;

        public My(@NonNull View itemView) {
            super(itemView);
            lineName = view.findViewById(R.id.lineName);
            color = view.findViewById(R.id.color);
        }
    }
}
